DockerClient

open class DockerClient(val config: DockerClientConfig = DockerClientConfig()) : ApiCacheHolder, AutoCloseable

Client for one Docker host, using fixed API version 1.51 and a Unix socket.

Reuse an instance for application-scoped work, or use Kotlin use for a short-lived client. close shuts down the owned HTTP client; raw exec/attach sessions must be closed separately. No API negotiation, Docker context discovery or automatic retry/reconnect is performed.

Import dev.limebeck.libs.docker.client.api.* to access containers, images, exec and other API groups.

Parameters

config

Serialization, endpoint and in-memory registry authentication settings.

See also

Samples

DockerClient(DockerClientConfig(
    connectionConfig = DockerClientConfig.ConnectionConfig.SocketConnection(socketPath),
)).use { docker ->
    docker.system.ping().getOrThrow()
    docker.containers.getList().getOrThrow().forEach { println(it.names) }
}

Constructors

Link copied to clipboard
constructor(config: DockerClientConfig = DockerClientConfig())

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val apiCache: MutableMap<Any, Any>
Link copied to clipboard
val client: HttpClient

Owned Ktor HTTP client. Prefer close or use for lifecycle management. Changing its configuration can affect all API groups sharing this client.

Link copied to clipboard

Cached Compose integration using this client's endpoint and lifetime.

Link copied to clipboard
Link copied to clipboard

Cached containers API bound to this client and its connection configuration.

Link copied to clipboard

Cached exec API bound to this client and its connection configuration.

Link copied to clipboard

Cached images API bound to this client and its connection configuration.

Link copied to clipboard
val json: Json
Link copied to clipboard

Cached networks API bound to this client and its connection configuration.

Link copied to clipboard

Cached Swarm API using this client's endpoint and lifetime.

Link copied to clipboard

Cached system API bound to this client and its connection configuration.

Link copied to clipboard

Cached volumes API bound to this client and its connection configuration.

Functions

Link copied to clipboard
fun apiPath(path: String): String

Builds the path shared by HTTP and raw hijack requests.

Link copied to clipboard
fun HttpRequestBuilder.applyAuthForRegistry(registry: String)
Link copied to clipboard
fun HttpRequestBuilder.applyConnectionConfig()
Link copied to clipboard
fun HttpRequestBuilder.applyStreamConfig()

Live streams may be idle indefinitely; the collector owns their lifetime.

Link copied to clipboard
suspend fun DockerClient.auth(authConfig: AuthConfig): Result<SystemAuthResponse, ErrorResponse>

Validates registry credentials through Docker and stores successful authentication in DockerClientConfig.auth.

Link copied to clipboard
open override fun close()

Closes the owned HTTP client. Repeated calls are safe. Stop collectors and close independently owned exec/attach sessions before shutdown. This method initiates shutdown without waiting for active HTTP calls to finish.

Link copied to clipboard
suspend fun <T> HttpResponse.consumeStream(block: suspend (ByteReadChannel) -> T): T

Validate transport completion as well as status; CIO can report a short body as clean EOF.

Link copied to clipboard
suspend fun DockerClient.createInteractiveSession(tty: Boolean, method: HttpMethod, path: String, parameters: Parameters = Parameters.Empty, headers: Map<String, String> = emptyMap(), body: ByteArray? = null): Result<ExecSession, ErrorResponse>
Link copied to clipboard

Probes the configured daemon using the SDK's versioned ping without changing daemon state. A successful probe establishes reachability/API acceptance, not permission for every Docker operation. Does not retry or close this client. Cancellation from the caller always propagates.

Link copied to clipboard

Describes an upstream transport exception without retrying or modifying it. Use for failures from HTTP calls, stream collection or exec/attach. Do not use to label application callback errors. Recognizes common exception names and OS messages/codes; unsupported/localized messages remain UNKNOWN. Cancellation is rethrown. Clean stream EOF has no exception and requires application-owned reconciliation.

Link copied to clipboard
suspend fun HttpResponse.errorResponse(): ErrorResponse

Handles bodyless HEAD errors and non-JSON daemon/proxy responses.

Link copied to clipboard
suspend fun HttpResponse.errorResult(): Result<Nothing, ErrorResponse>

An HTTP error Result retaining safe request context for getOrThrow.

Link copied to clipboard
Link copied to clipboard
inline suspend fun <T> HttpResponse.parse(): Result<T, ErrorResponse>
Link copied to clipboard
suspend fun HttpResponse.requireStreamSuccess()

Cold streams surface HTTP failures during collection, before decoding data.

Link copied to clipboard
suspend fun HttpResponse.validateImageProgress(): Result<Unit, ErrorResponse>

Docker can report an operation failure inside a successful NDJSON response.

suspend fun <TAux> HttpResponse.validateImageProgress(auxSerializer: KSerializer<TAux>, onProgress: suspend (ImageProgress<TAux>) -> Unit): Result<Unit, ErrorResponse>
Link copied to clipboard
inline suspend fun HttpResponse.validateOnly(): Result<Unit, ErrorResponse>